<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Session;
//use think\Db;

class Common extends Controller{
    
    /**
     * 首页顶部菜单
     * @author liuwuchen 2017-09-07
     * @return html
     */
    public function menu() {
        return $this->fetch( 'base/menu' );
    }
    
    /**
     * 首页
     * @author liuwuchen 2017-09-07
     * @return html
     */
    public function home() {
        
        $this->assign( 'static', 'http://zaixianjiaoyu.com/static/'.request()->module() );
        return $this->fetch();
    }

    /**
     * 用户信息
     * @return html
     */
    public function userInfo() {
        //检测当前是否登录
        if( !session( 'admin.user_auth' ) ) {
            $this->redirect( url( 'login/index' ) );
        } else {
            if( request()->isPost() ) {
                $data        = input();
                $auth_member = model( 'AuthMember' );
                if( $data['password'] ) {
                    $valid = new \app\admin\validate\AuthMember;
                } else {
					$valid = new \app\admin\validate\AuthMember;
                    //$valid   = \think\Loader::validate( "AuthMember" )->scene( 'read.html' );
                }
                if( !$valid->check( $data ) ) {
                    $this->error( $valid->getError() );
                } else {
                    if( $auth_member->editMember( $data, ['uid'=>$data['uid']] ) ) {
                        $this->success( '编辑成功' );
                    } else {
                        $this->error( '编辑失败' );
                    }
                }
            } else {
                //当前登录用户
                $user_auth = session( 'admin.user_auth' );
                $uid       = $user_auth['uid'];
                $info      = model( 'AuthMember' )->getFindOne( $uid );
                $this->assign( 'find', $info );
                $domain = config( 'url_domain' );
                $this->assign( 'static', $domain.'/static/'.request()->module() );
                return $this->fetch();
            }
        }
    }

}